<?php
/**
 * V7
 */
class data_guest extends data {
	public function __construct() {
		parent::__construct();
		
	}
	/**
	 * @param int $id		// hot表中的主键id
	 */
	public function one_article ($id) {
		$id = intval($id);
		
		if ($id) {
			$execute = $this->db->execute('
				select
					home_hot.id		AS id,
					home_hot.article_id	AS article_id,
					home_hot.article_id	AS content_id,
					home_hot.user_id		AS user_id,
					home_hot.article_title	AS title,
					"0000-00-00 00:00:00"	AS dt,
					home_hot.url_id		AS url_id,
					home_hot.url		AS url
				from
					home_hot
				where
					id = "'.$id.'"
			');
			if ($execute) {
				return $execute[0];
			} else return false;
		} else return false;
	}
	
	// ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### ### V7### 
	
	public function ls_hot () {
		$execute = $this->db->execute('
			select
				*
			from
				home_hot
			where
				1
			order by
				home_hot.id DESC
		');
		return $execute;
	}
	public function ls_circle () {
		$execute = $this->db->execute('
			select
				circle.*
			from
				home_hot_circle, circle
			where
				circle.id		= home_hot_circle.circle_id	and
				circle.privacy 	= "public"
			order by
				home_hot_circle.id DESC
		');
		if (is_array($execute)) {
			foreach ($execute as $k=>$v) {
				$execute[$k]['articles'] = $this->db->execute('
					select
						circle_article.id		AS id,
						save_article.id		AS article_id,
						save_article.title		AS title,
						save_article.img_0		AS img_0,
						article_url.url		AS url,
						users.nickname		AS user_nickname
					from
						circle_article, save_article, article_url, users
					where
						circle_article.circle_id	= "'.$v['id'].'"			and
						save_article.id		= circle_article.article_id		and
						article_url.id		= save_article.url_id		and
						users.id			= save_article.user_id
					order by
						circle_article.id DESC
					limit
						4
				');
				$execute[$k]['members'] = $this->db->execute('
					select
						users.id,
						users.nickname
					from
						circle_member, users
					where
						circle_member.circle_id		= "'.$v['id'].'"			and
						(circle_member.type = "member" or circle_member.type = "admin" or circle_member.type = "founder")	and
						users.id				= circle_member.user_id
					order by
						circle_member.total_articles_by_me DESC
					limit
						10
				');
			}
			return $execute;
		} else return false;
	}
}
?>